package com.lindroy.androidplayer.ui.adapter

import androidx.lifecycle.LifecycleOwner
import com.lindroy.androidplayer.base.adapter.BaseListAdapter
import com.lindroy.androidplayer.databinding.SearchHotKeyItemBinding
import com.lindroy.androidplayer.interfaces.OnItemChildClickListener
import com.lindroy.androidplayer.logic.model.SearchHotKeyResp
import com.lindroy.androidplayer.viewmodels.HotKeyItemViewModel

/**
 * @author Lin
 * @date 2022/3/8
 * @function
 */
class SearchHotKeyAdapter(owner: LifecycleOwner) :
    BaseListAdapter<HotKeyItemViewModel, SearchHotKeyItemBinding>(owner) {

    fun setNewData(list: List<SearchHotKeyResp>) {
        setData(list.map {
            HotKeyItemViewModel(
                id = it.id,
                link = it.link,
                name = it.name,
                visible = it.visible
            )
        })
    }

    override fun SearchHotKeyItemBinding.onBindViewHolder(
        item: HotKeyItemViewModel,
        position: Int
    ) {
        vm = item
    }

    override fun SearchHotKeyItemBinding.onBindChildClick(itemClickListener: OnItemChildClickListener<HotKeyItemViewModel>) {
        itemClick = itemClickListener
    }

    override fun artItemsTheSame(
        oldItem: HotKeyItemViewModel,
        newItem: HotKeyItemViewModel
    ) = oldItem.id == newItem.id

    override fun areContentsTheSame(
        oldItem: HotKeyItemViewModel,
        newItem: HotKeyItemViewModel
    ) = oldItem.id == newItem.id
}